package Reflect;

import Reflect.annotation.AutoRunClass;
import Reflect.annotation.AutoRunMethod;

import java.lang.reflect.Method;
import java.util.Scanner;

public class Test4 {
    public static void main(String[] args) throws Exception {
        System.out.println("请输入类");
        Scanner sc=new Scanner(System.in);
        Class cla=Class.forName(sc.next());
        if (cla.isAnnotationPresent(AutoRunClass.class)){
        Object obj=cla.newInstance();
        Method[] methods = cla.getMethods();

        for (Method method:methods){
            if (method.isAnnotationPresent(AutoRunMethod.class)) {
                System.out.println(method.getName() + "有注解");
                method.invoke(obj);
            }
        }
        }else {
            System.out.println("类没有注解");
        }
    }
}
